pub fn convert_base(num_str: &str, to_base: u32) -> String {
    let mut from_base = 10;
    let mut from_num = num_str;

    // split the string to get from_base and from_num
    if let Some(s1) = num_str.strip_suffix(')') {
        if let Some(index) = s1.find('(') {
            from_base = s1[index + 1..].parse::<u32>().unwrap();
            from_num = &s1[..index];
        }
    }

    // calc total value
    let mut total: u32 = 0;
    for c in from_num.chars() {
        let digit = c.to_digit(from_base).unwrap();
        total = total * from_base + digit;
    }

    // convert to to_base
    let mut result = String::new();
    while total > 0 {
        let digit = total % to_base;
        result.insert(
            0,
            match digit {
                0..=9 => (b'0' + digit as u8) as char,
                _ => (b'a' + (digit - 10) as u8) as char,
            },
        );
        total /= to_base;
    }
    result
}
